import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
* Company: QuantaNetwork BeiJing Ltd
* Author : 张彦龙
* DateTime: Nov 26, 2008  4:51:20 PM
*/
public class UDPServer
{
	public static void main(String[] args)
	{
		try
		{
			DatagramSocket datagramSocket = new DatagramSocket(10001);
			while (true)
			{
				DatagramPacket packet = new DatagramPacket(new byte[4096], 4096);
				datagramSocket.receive(packet);
				if (packet.getData() != null)
				{
					String msg = new String(packet.getData(), 0, packet.getData().length);
					System.out.println("Client:" + packet.getAddress() + ":" + packet.getPort());
					packet.setData("我是龙哥".getBytes());
					datagramSocket.send(packet);
				}
			}
		}
		catch (SocketException e)
		{
			e.printStackTrace();
		}
		catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
